package com.java.common;

import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.util.Properties;

public class ConfigEntity {
	
    public ConfigEntity() {
    	init();
    }
    
    public static boolean  debug = false;
    
    public static String   testDomainPrefix = ""; 
    public static String   enableAdmin      = "";
    public static String   enableCp         = "";
    public static String   enableCompany    = "";
    public static String   enableTutor      = "";
    
    public static String[] enableDomain     = null;

    public static String   sendEmail        = ""; 
    
    public static void init() {
        Properties props = new Properties();  
        URL settingsUrl = Thread.currentThread().getContextClassLoader().getResource( "applicatoinConfig.properties" );
        
        // Load settings
        InputStream in = null;
        try {
            in = settingsUrl.openStream();
            props.load( in );
            
            testDomainPrefix = props.getProperty( "domain.testDomainPrefix" ).trim();

            enableAdmin      = props.getProperty( "domain.enableAdmin" ).trim();
            enableCp         = props.getProperty( "domain.enableCp" ).trim();
            enableCompany    = props.getProperty( "domain.enableCompany" ).trim();
            enableTutor      = props.getProperty( "domain.enableTutor" ).trim();

            sendEmail        = props.getProperty( "email.sendEmail" ).trim();

            if (debug) {
            	System.out.println( "## Config Entity Init values ##");
            	System.out.println( "domain.testDomainPrefix = " + testDomainPrefix);
            	System.out.println( "domain.enableAdmin = " + enableAdmin);
            	System.out.println( "domain.enableCp = " + enableCp);
            	System.out.println( "domain.enableCompany = " + enableCompany);
            	System.out.println( "domain.enableTutor = " + enableTutor);       	
            	System.out.println( "domain.sendEmail = " + sendEmail);     
            }
        } catch ( IOException e ) {
            System.out.println("## ERROR : applicatoinConfig.properties INIT FAILED!!" );
            
        } finally {
            try {
            	if(in != null)
                in.close();
            } catch ( IOException e ) {}
        }        
    }

    public String getTestDomainPrefix() {
    	return this.testDomainPrefix;
    }

    public String getEnableAdmin() {
    	return this.enableAdmin;
    }
    public String getEnableTestAdmin() {
    	return this.testDomainPrefix + this.enableAdmin;
    }
    public String getEnableCp() {
    	return this.enableCp;
    }
    public String getEnableTestCp() {
    	return this.testDomainPrefix + this.enableCp;
    }
    public String getEnableCompany() {
    	return this.enableCompany;
    }
    public String getEnableTestCompany() {
    	return this.testDomainPrefix + this.enableCompany;
    }
    public String getEnableTutor() {
    	return this.enableTutor;
    }
    public String getEnableTestTutor() {
    	return this.testDomainPrefix + this.enableTutor;
    }
    
    public String[] getEnableDomain() {
    	return this.enableDomain;
    }
    
    public String getSendEmail() {
    	return this.sendEmail ;
    }
}
